package com.mingqijia.gassafety.console.migrate.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.console.migrate.service.MigrateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 数据迁移
 * @Author: zero
 * @CreateTime: 2022-11-30
 */
@Slf4j
@Api(tags = "数据迁移")
@RestController
@RequestMapping(value = "/webSocket/migrate", produces = MediaType.APPLICATION_JSON_VALUE)
public class MigrateController {



    @Resource
    private MigrateService migrateService;

    @GetMapping("/migrateData")
    public CommonResponse<List<Integer>> consumer(){
        try {
            return CommonResponse.success(migrateService.migrateData());
        } catch (Exception e) {
            return CommonResponse.failure(e.getMessage());
        }
    }

    @GetMapping("/unBoundDtu")
    public CommonResponse unBoundDtu(){
        try {
            migrateService.unBoundDtu();
            return CommonResponse.success("成功");
        } catch (Exception e) {
            return CommonResponse.failure(e.getMessage());
        }
    }
//    弃用
//    @GetMapping("/migrateDataByIdList")
//    public CommonResponse<List<Integer>> migrateDataByIdList(@RequestParam("consumerId") List<Integer> idList){
//        try {
//            return CommonResponse.success(migrateService.migrateDataByIdList(idList));
//        } catch (Exception e) {
//            return CommonResponse.failure(e.getMessage());
//        }
//    }

    /**
     * 客户与燃气户关系excel导入
     * @return
     */
    @GetMapping("import")
    @ApiOperation(value = "设备excel导入")
    public CommonResponse<Object> importData(@ApiParam(value = "file") MultipartFile file){
        migrateService.importData(file);
        return CommonResponse.success(null);
    }
}
